package com.cj.simple;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import com.cj.library.widget.dialog.CJDialog;
import com.cj.library.widget.dialog.DatePickerDialog;
import com.cj.library.widget.dialog.LoadingDialog;
import com.cj.library.widget.utiles.ToastUtile;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by JiangGe on 2016/9/15.
 */
public class DIalogActivity extends Activity {

    private CJDialog dialog;
    private Context mCtx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);
        mCtx = getApplicationContext();
    }

    public void show(View view) {
        dialog = new CJDialog.Builder(this)
                .setContentView(R.layout.dialog_page1)
                .setWindowAnimations(R.style.dialogWindowAnim)
                .create();
        dialog.getViewHolder()
                .setOnClickListener(R.id.cancel, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dialog.dismiss();
                    }
                })
                .setOnClickListener(R.id.sure, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ToastUtile.show(DIalogActivity.this, "点击了确定");
                    }
                });
        dialog.show();
    }

    DatePickerDialog dateDialog;

    public void dateDialog(View view) {
        dateDialog = new DatePickerDialog(this);
        dateDialog.setTitle("选择日期");
        dateDialog.hideDay();
        dateDialog.setOnDateSelectedListener(new DatePickerDialog.OnDateSelectedListener() {
            @Override
            public void onDateSelectedListener(int year, int month, int day) {
                ToastUtile.show(mCtx, year + "年-" + month + "月-" + day + "日");
            }
        });
        dateDialog.show();
    }

    public void circleLoding(View view) {
        LoadingDialog dialog = new LoadingDialog(this);
        dialog.setMsg("拼命加载中");
        dialog.show();
    }

    CJDialog cjDialog;

    public void cjdialog(View view) {
        cjDialog = new CJDialog.Builder(this)
                .setContentView(R.layout.activity_rotate_view)
                .setWight(WindowManager.LayoutParams.WRAP_CONTENT)
                .setHeight(WindowManager.LayoutParams.WRAP_CONTENT)
                .setBackAlpha(0.5f)
                .setCancelable(true)
                .setCanceledOnTouchOutside(false)
                .setOnShowListener(new DialogInterface.OnShowListener() {
                    @Override
                    public void onShow(DialogInterface dialogInterface) {
                        new Timer().schedule(new TimerTask() {
                            @Override
                            public void run() {
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        cjDialog.dismiss();
                                    }
                                });
                            }
                        }, 5000);
                    }
                })
                .setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialogInterface) {
                        ToastUtile.show(DIalogActivity.this, "取消了");
                    }
                })
                .setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        ToastUtile.show(DIalogActivity.this, "关闭了");
                    }
                })
                .create();
        cjDialog.getViewHolder()
                .setText(R.id.dialog_content, "加载中...");
        cjDialog.show();
    }
}
